package org.testis.webautomationmodule.ui.objects;

import org.testis.data.AtofModuleConstants;
import org.testis.logging.AtofLogLevel;
import org.testis.utils.TerminalApplicationExecutor;
import org.testis.webautomationmodule.services.SeleniumWebAutomationProvider;
import org.testis.webautomationmodule.ui.UIFormFieldDecorator;
import java.io.IOException;

public class UIFileSelector extends UIFormFieldDecorator {

    public UIFileSelector(String id,
            String fileToOpen) {
        super(id);
        setValue(fileToOpen);
    }

    @Override
    protected boolean setBehavior() {
        if (checkAvailableForAction()) {
            putLog(" selecting file for input with id " + getId()
                    + " and value with " + getValue());
            getWebAutomationImpl().type(getId(),
                    getValue());
            String value = getWebAutomationImpl().getValue(getId());
            if (getValue().equals(value)) {
                putLog(value
                        + " file selected successfully");
                return true;
            } else {
                putLog("Could not select file " + getValue() + "...",
                        AtofLogLevel.ERROR);
                return false;
            }

        }
        return false;
    }
}

